﻿<template>
  <div class="wrapper">
    <!-- 面包屑导航栏区域 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>人事管理</el-breadcrumb-item>
      <el-breadcrumb-item>员工添加</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="body">
      <!-- 添加表单 -->
      <div slot="header" class="clearfix">
        <span>添加员工</span>
      </div>
      <el-form :inline='true' label-position='top' ref="form" :rules="rules" :model="addForm" label-width="100px">
        <el-form-item label="姓名" prop="name" > 
          <el-input v-model="addForm.name" style="width:320px;"></el-input>
        </el-form-item>
        <el-form-item label="年龄" prop="age"> 
          <el-input v-model="addForm.age" type="number" style="width:320px;"></el-input>
        </el-form-item>
        <el-form-item label="联系电话"  prop="phone"> 
          <el-input v-model="addForm.phone" style="width:650px;"></el-input>
        </el-form-item><br>
        <el-form-item label="性别" prop="sex">
          <el-radio-group v-model="addForm.sex">
            <el-radio :label="1">男</el-radio>
            <el-radio :label="0">女</el-radio>
        </el-radio-group>
        </el-form-item><br>
        <el-form-item label="家庭住址" prop="address" > 
          <el-input v-model="addForm.address" style="width:650px;"></el-input>
        </el-form-item>
        <el-form-item label="职位" prop="position"> 
          <el-input v-model="addForm.position" style="width:650px;"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width:650px" @click="onSubmit('form')">添加</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      addForm: {
          name: '',
          age: '',
          phone: '',
          sex: 1,
          address: '',
          position: '',
        },
         rules: {
          name: [
            { required: true, message: '请输入员工姓名', trigger: 'blur' },
            { min: 2, max: 6, message: '长度在 2 到 6 个字符', trigger: 'blur' }
          ],
          age:[
            { required: true, message: '请输入员工年龄', trigger: 'blur' },
            { min: 1, max: 3, message: '长度在 1 到 3 个字符', trigger: 'blur' }
          ],
          phone:[
            { required: true, message: '请输入员工年龄', trigger: 'blur' },
            { min: 1, max: 3, message: '长度在 1 到 3 个字符', trigger: 'blur' }
          ],
          phone:[
            { required: true, message: '请输入员工年龄', trigger: 'blur' },
            { min: 1, max: 3, message: '长度在 1 到 3 个字符', trigger: 'blur' }
          ],
          sex:[
            {required:true,}
          ],
          address:[
            { required: true, message: '请输入员工住址', trigger: 'blur' },
            { min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur' }
          ],
          position:[
            { required: true, message: '请输入员工职位', trigger: 'blur' },
            { min: 1, max: 15, message: '长度在 1 到 15 个字符', trigger: 'blur' }
          ],

         }
    };
  },
  watch: {},
  computed: {},
  methods: {
    onSubmit(form){
      this.$refs[form].validate(async (valid) => {
          if (!valid) return ;
          const{data:res} = await this.$http.get('',) 
          if(data.meta.status !== 200){
            return this.$message.error('错误请稍后再试')
          }
          this.$message.success("员工添加成功")
          
        });

    },
  },
  created() {},
  mounted() {}
};
</script>
<style lang="less" scoped>

.body{
  width: 800px;


}
</style>